package com.giscloud.commons.utils;

import com.giscloud.commons.enums.ResultEnum;
import com.giscloud.commons.model.Result;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

/**
 * @Author:giscloud
 * @Description:
 * @Date: 9:17 2019/9/12
 * @Modified By:
 */
public class ResultUtil {

    public static Result success(Object object) {
        Result result = new Result();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setData(object);
        return result;
    }

    public static Result success(String msg) {
        Result result = new Result();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(msg);
        result.setData(null);
        return result;
    }
    public static Result success(Object object,String msg) {
        Result result = new Result();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(msg);
        result.setData(object);
        return result;
    }

    public static Result success() {
        return success(null);
    }

    public static Result error(int code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setSuccess(Boolean.FALSE);
        return result;
    }

    public static Result error(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        result.setSuccess(Boolean.FALSE);
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(ResultEnum.FAIL.getCode());
        result.setMsg(msg);
        result.setSuccess(Boolean.FALSE);
        return result;
    }
}
